#pragma once

/*
 * 登录处理类
 */
class PwdHandler : public JsonRequest<LoginHandler>
{
public:
	bool response()
	{
		std::string		user;
		std::string		pwd;
		std::string		token;
		std::string		uid;
		sql_string<>	sql;

		// 获取用户id
		request::get("token", token);
		sql.format("select uid from t_session where token='%q'",
				token.c_str());
		sql::signalQuery(sql.c_str(), &uid);
		if(false == request::get("pwd", pwd))
		{
			err << "invalid paramter";
			return false;
		}

		// 设置密码
		sql.format("update t_admin set passwd=password('%q') where id=%s",
			pwd.c_str(), uid.c_str());
		if( 1 != sql::execute(sql.c_str()) )
		{
			err << "set password failed";
			return false;
		}

		json.push_back(JSONNode("errno", 0));
		return true;
	}

};

